package cc.messcat.util;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

@Component  
public class JsonDateSerializer extends JsonSerializer<Date> {  
  
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
      
    @Override  
    public void serialize(Date date, JsonGenerator gen, SerializerProvider arg2)  
            throws IOException, JsonProcessingException {
    	//设置时区
    	format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
        String formattedDate = format.format(date);   
        gen.writeString(formattedDate);   
    }  
      
}  